'use strict';
const db = uniCloud.database()
const $ = db.command.aggregate
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const{
		user_id,
		title = [],
		content = []
	} = event
	//获取数据
	let user = await db.collection('user').doc(user_id).get()
	//封装文章内容
	// let passageObj={
	// 	passage_id:setID(5),
	// 	author_name:user.author_name,
	// 	passage_content:content,
	// 	cover:user.cover
		
	// }
	
	// 上传数据表
	await db.collection("myArticle").add({
	user_id:user_id,
	title:title,
	content:content
	})
	//返回数据给客户端
	return {
		code:200,
		msg:"文章上传成功"
	}
};
// 生成文章id
function setID(length){
	return Number(Math.random().toString().substr(3,length)+Date.now()).toString(36)
}